Full source code website bán hàng thương mại điện tử gần giống shopee
473.365 lượt xem;
1 <?php
2 /*
3 * getmxrr.php
4 *
5 * @(#) $Header: /home/mlemos/cvsroot/PHPlibrary/getmxrr.php,v 1.1 2002/06/21 05:33:42 mlemos Exp $
6 *
7 */
8
9 /* ------------------------------------------------------------------------
10
11 PHPresolver - PHP DNS resolver library
12 Version 1.1
13
14 Copyright (c) 2001, 2002 Moriyoshi Koizumi <koizumi@ave.sytes.net>
15 All Rights Reserved.
16
17 This library is free software; you can redistribute it and/or modify it
18 under the terms of the GNU Lesser General Public License as published
19 by the Free Software Foundation; either version 2.1 of the License, or any
20 later version.
21
22 This library is distributed in the hope that it will be useful, but
23 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
25 License for more details.
26
27 You should have received a copy of the GNU Lesser General Public License
28 along with this library; if not,
29 write to the Free Software Foundation, Inc.,
30 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31
32 ------------------------------------------------------------------------ */
33
34 if(IsSet($_NAMESERVERS)
35 && (GetType($_NAMESERVERS)!="array"
36 || count($_NAMESERVERS)==0))
37 Unset($_NAMESERVERS);
38
39 /***************************************************************************
40 Description
41
42 $_NAMESERVER[]
43
44 The array that contains IP addresses or domain names of name servers
45 used for DNS resolution.
46 If nothing is set before require()'ing this library, the values will
47 automatically prepared.
48
49 bool getmxrr( string $hostname, arrayref $mxhosts, arrayref $weight );
50
51 This function works in the same way as getmxrr(), however the
52 third parameter cannot be omitted. If you need no MX preference
53 information, please do like:
54
55 getmxrr( 'example.com', $mxhosts, ${''} );
56
57
58 -------------------------------------------------------------------------
59 Configuration
60
61 If you are doing with win32 environments and don't set $_NAMESERVER
62 manually, make sure that ipconfig.exe is within the PATH.
63 ipconfig.exe is generally distributed with any Microsoft(R) Windows
64 distributions except for Windows 95.
65
66 ***************************************************************************/
67
68 require_once( 'DNS.php' );
69
70 /* rewrite this path to the same as the box's configuration
71 if you run scripts on *NIX platforms */
72 define( 'RESOLV_CONF_PATH', '/etc/resolv.conf' );
73
74 if( !isset( $_NAMESERVERS ) ) {
75 $_NAMESERVERS = array();
76 if( strncmp( PHP_OS, "WIN", 3 ) == 0 ) {
77 unset( $res );
78 exec( 'ipconfig /all', $res );
79 $cnt = count( $res );
80 for( $i = 0; $i < $cnt; ++$i ) {
81 if( strpos( $res[$i], 'DNS Servers' ) !== false ) {
82 $_NAMESERVERS[] = substr( $res[$i], strpos( $res[$i], ': ' ) + 2 );
83 break;
84 }
85 }
86 while( $i<$cnt-1 && strpos( $res[++$i], ':' ) === false ) {
87 $_NAMESERVERS[] = trim( $res[$i] );
88 }
89 } elseif( file_exists( RESOLV_CONF_PATH ) ) {
90 $lines = file( RESOLV_CONF_PATH );
91 $cnt = count( $lines );
92 for( $i = 0; $i < $cnt; ++$i ) {
93 list( $dr, $val ) = split( '[ \t]', $lines[$i] );
94 if( $dr == 'nameserver' ) {
95 $_NAMESERVERS[] = rtrim( $val );
96 }
97 }
98 unset( $lines );
99 }
100 }
101
102 if(count($_NAMESERVERS))
103 $__PHPRESOLVER_RS = new DNSResolver( $_NAMESERVERS[0] );
104 else
105 {
106 Unset($_NAMESERVERS);
107 Unset($__PHPRESOLVER_RS);
108 }
109
110 function GetMXRR( $hostname, &$mxhosts, &$weight ) {
111 global $__PHPRESOLVER_RS;
112 if(!IsSet($__PHPRESOLVER_RS))
113 return(false);
114 $dnsname = & DNSName::newFromString( $hostname );
115 $answer = & $__PHPRESOLVER_RS->sendQuery(
116 new DNSQuery(
117 new DNSRecord( $dnsname, DNS_RECORDTYPE_MX )
118 )
119 );
120 if( $answer === false || $answer->rec_answer === false ) {
121 return false;
122 } else {
123 $i = count( $answer->rec_answer );
124 $mxhosts = $weight = array();
125 while( --$i >= 0 ) {
126 if( $answer->rec_answer[$i]->type == DNS_RECORDTYPE_MX ) {
127 $rec = &$answer->rec_answer[$i]->specific_fields;
128 $mxhosts[] = substr( $rec['exchange']->getCanonicalName(), 0, -1 );
129 $weight[] = $rec['preference'];
130 }
131 }
132 return true;
133 }
134 }
135
136 ?>
2 /*
3 * getmxrr.php
4 *
5 * @(#) $Header: /home/mlemos/cvsroot/PHPlibrary/getmxrr.php,v 1.1 2002/06/21 05:33:42 mlemos Exp $
6 *
7 */
8
9 /* ------------------------------------------------------------------------
10
11 PHPresolver - PHP DNS resolver library
12 Version 1.1
13
14 Copyright (c) 2001, 2002 Moriyoshi Koizumi <koizumi@ave.sytes.net>
15 All Rights Reserved.
16
17 This library is free software; you can redistribute it and/or modify it
18 under the terms of the GNU Lesser General Public License as published
19 by the Free Software Foundation; either version 2.1 of the License, or any
20 later version.
21
22 This library is distributed in the hope that it will be useful, but
23 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
25 License for more details.
26
27 You should have received a copy of the GNU Lesser General Public License
28 along with this library; if not,
29 write to the Free Software Foundation, Inc.,
30 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31
32 ------------------------------------------------------------------------ */
33
34 if(IsSet($_NAMESERVERS)
35 && (GetType($_NAMESERVERS)!="array"
36 || count($_NAMESERVERS)==0))
37 Unset($_NAMESERVERS);
38
39 /***************************************************************************
40 Description
41
42 $_NAMESERVER[]
43
44 The array that contains IP addresses or domain names of name servers
45 used for DNS resolution.
46 If nothing is set before require()'ing this library, the values will
47 automatically prepared.
48
49 bool getmxrr( string $hostname, arrayref $mxhosts, arrayref $weight );
50
51 This function works in the same way as getmxrr(), however the
52 third parameter cannot be omitted. If you need no MX preference
53 information, please do like:
54
55 getmxrr( 'example.com', $mxhosts, ${''} );
56
57
58 -------------------------------------------------------------------------
59 Configuration
60
61 If you are doing with win32 environments and don't set $_NAMESERVER
62 manually, make sure that ipconfig.exe is within the PATH.
63 ipconfig.exe is generally distributed with any Microsoft(R) Windows
64 distributions except for Windows 95.
65
66 ***************************************************************************/
67
68 require_once( 'DNS.php' );
69
70 /* rewrite this path to the same as the box's configuration
71 if you run scripts on *NIX platforms */
72 define( 'RESOLV_CONF_PATH', '/etc/resolv.conf' );
73
74 if( !isset( $_NAMESERVERS ) ) {
75 $_NAMESERVERS = array();
76 if( strncmp( PHP_OS, "WIN", 3 ) == 0 ) {
77 unset( $res );
78 exec( 'ipconfig /all', $res );
79 $cnt = count( $res );
80 for( $i = 0; $i < $cnt; ++$i ) {
81 if( strpos( $res[$i], 'DNS Servers' ) !== false ) {
82 $_NAMESERVERS[] = substr( $res[$i], strpos( $res[$i], ': ' ) + 2 );
83 break;
84 }
85 }
86 while( $i<$cnt-1 && strpos( $res[++$i], ':' ) === false ) {
87 $_NAMESERVERS[] = trim( $res[$i] );
88 }
89 } elseif( file_exists( RESOLV_CONF_PATH ) ) {
90 $lines = file( RESOLV_CONF_PATH );
91 $cnt = count( $lines );
92 for( $i = 0; $i < $cnt; ++$i ) {
93 list( $dr, $val ) = split( '[ \t]', $lines[$i] );
94 if( $dr == 'nameserver' ) {
95 $_NAMESERVERS[] = rtrim( $val );
96 }
97 }
98 unset( $lines );
99 }
100 }
101
102 if(count($_NAMESERVERS))
103 $__PHPRESOLVER_RS = new DNSResolver( $_NAMESERVERS[0] );
104 else
105 {
106 Unset($_NAMESERVERS);
107 Unset($__PHPRESOLVER_RS);
108 }
109
110 function GetMXRR( $hostname, &$mxhosts, &$weight ) {
111 global $__PHPRESOLVER_RS;
112 if(!IsSet($__PHPRESOLVER_RS))
113 return(false);
114 $dnsname = & DNSName::newFromString( $hostname );
115 $answer = & $__PHPRESOLVER_RS->sendQuery(
116 new DNSQuery(
117 new DNSRecord( $dnsname, DNS_RECORDTYPE_MX )
118 )
119 );
120 if( $answer === false || $answer->rec_answer === false ) {
121 return false;
122 } else {
123 $i = count( $answer->rec_answer );
124 $mxhosts = $weight = array();
125 while( --$i >= 0 ) {
126 if( $answer->rec_answer[$i]->type == DNS_RECORDTYPE_MX ) {
127 $rec = &$answer->rec_answer[$i]->specific_fields;
128 $mxhosts[] = substr( $rec['exchange']->getCanonicalName(), 0, -1 );
129 $weight[] = $rec['preference'];
130 }
131 }
132 return true;
133 }
134 }
135
136 ?>